//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package net.mingsoft.basic.action.web;

import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.CircleCaptcha;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import net.mingsoft.basic.constant.e.SessionConstEnum;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Api(
        tags = {"前端-基础接口"}
)
@Controller("codeAction")
@RequestMapping({"code"})
public class CodeAction {
    private int imgWidth = 100;
    private int imgHeight = 50;
    @Value("${ms.rand-code.length:4}")
    private int length;
    @Value("${ms.rand-code.circle:8}")
    private int circle;

    public CodeAction() {
    }

    @ApiOperation("返回验证码图片")
    @GetMapping(
            produces = {"image/jpeg"}
    )
    @ResponseBody
    public byte[] index(HttpServletRequest req, HttpServletResponse res, HttpSession session) throws IOException {
        CircleCaptcha captcha = CaptchaUtil.createCircleCaptcha(this.imgWidth, this.imgHeight, this.length, this.circle);
        session.setAttribute(SessionConstEnum.CODE_SESSION.toString(), captcha.getCode());
        return captcha.getImageBytes();
    }
}
